package com.example.simple_cheat;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class friendsAdapter extends RecyclerView.Adapter <friendsAdapter.ViewHolder>{
    private List<friendsdetail> friendlist;
    private Context context;

    public friendsAdapter(Context context,List<friendsdetail> templist){
        this.context = context;
        friendlist = templist;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.friends_detail,parent,false);
        final ViewHolder holder = new ViewHolder(view);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context,MainActivity.class);
                intent.putExtra("name",holder.friendsname.getText().toString());
                context.startActivity(intent);

            }
        });
        return new friendsAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        friendsdetail tempfriend = friendlist.get(position);
        holder.friendsname.setText(tempfriend.getName());
        holder.littleFriendsImage.setImageResource(tempfriend.getImageId());
    }

    @Override
    public int getItemCount() {
        return friendlist.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView littleFriendsImage;
        TextView friendsname;
        View friendview;
        public ViewHolder(View view){
            super(view);
            friendview = view;
            littleFriendsImage = (ImageView)view.findViewById(R.id.littleheadImage);
            friendsname = (TextView)view.findViewById(R.id.friend_name);

        }
    }
}
